import config from '@/config/config.js';
import http from '@/api/http.js'

/**
 * 申明一个常量对象
 * @type {{}}
 */
const classifyRequest={
    // 可以申明一些方法
    /**
     * 加载所有的分类
     * @param parentId 父任务编号
     */
    loadClassify(classify, parentId=0,callBack){
        // 获取token
        let token = localStorage.getItem("token");
        let url= config.mdBaseUrl + "/materialClassify/list?";
        if (classify.classifyName != null && classify.classifyName != '' || classify.classifyStatus != 0) {
            if (classify.classifyName != null && classify.classifyName != '' && classify.classifyStatus == 0) {
                url += "classifyName=" + classify.classifyName;
            }
            if (classify.classifyStatus != 0 && classify.classifyName == null || classify.classifyName == '') {
                url += "classifyStatus=" + classify.classifyStatus;
            }
            if (classify.classifyName != null && classify.classifyName != '' && classify.classifyStatus != 0) {
                url += "classifyName=" + classify.classifyName + "&classifyStatus=" + classify.classifyStatus;
            }
        } else {
            url += "parentId=" + parentId;
        }
        if(token){
            http.get(url,callBack);
        }else{
            callBack(undefined);
        }

    },
    save(classify,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/save";
            http.post(url,classify,callBack);
        }else {
            callBack(undefined);
        }
    },
    selectById(classifyId,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/selectById?classifyId=" + classifyId;
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    },
    updateClassifyById(classify,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/update";
            http.put(url,classify,callBack);
        } else {
            callBack(undefined);
        }
    },
    countSubclassify(classifyId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/countSubclassify?classifyId=" + classifyId;
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    },deleteClassifyById(classifyId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/delete?classifyId=" + classifyId;
            http.delete(url,callBack);
        } else {
            callBack(undefined);
        }
    },getTree(parentId = 0,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.mdBaseUrl + "/materialClassify/getTree?parentId=" + parentId;
            http.get(url,callBack);
        } else {
            callBack(undefined);
        }
    }
}
// 将我们的请求对象暴露处理
export default classifyRequest;